<template>
  <div class="body">
    <div class="box">
      <img src="../assets/logo.png" width="80" />
      <h1>实施平台</h1>
      <div class="form">
        <a-form :form="form" @submit="handleSubmit">
          <a-form-item>
            <a-input
              v-decorator="[
                'username',
                {
                  rules: [{ required: true, message: '请输入用户名!' }],
                },
              ]"
              placeholder="请输入用户名"
            >
              <a-icon
                slot="prefix"
                type="user"
                style="color: rgba(0, 0, 0, 0.25)"
              />
            </a-input>
          </a-form-item>
          <a-form-item>
            <a-input
              v-decorator="[
                'password',
                {
                  rules: [{ required: true, message: '请输入密码!' }],
                },
              ]"
              type="password"
              placeholder="请输入密码"
            >
              <a-icon
                slot="prefix"
                type="lock"
                style="color: rgba(0, 0, 0, 0.25)"
              />
            </a-input>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" html-type="submit" class="submit">
              登录
            </a-button>
          </a-form-item>
        </a-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  beforeCreate() {
    this.form = this.$form.createForm(this, { name: "normal_login" });
  },
  methods: {
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$store
            .dispatch("login", {
              ...values,
            })
            .then(() => {
              this.$router.push({ path: "/" });
            })
            .catch((err) => {
              this.$message.error(err);
            });
        }
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.body {
  height: 100%;
  background: url("../assets/bg.jpg") repeat;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .box {
    width: 400px;
    text-align: center;
    position: relative;
    top: -50px;

    h1 {
      font-family: "Times New Roman", Times, serif, sans-serif;
      font-size: 30px;
      color: #ffffff;
      margin: 20px 0;
    }

    .form {
      width: 100%;
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.1);
      padding: 30px 50px;

      h3 {
        font-size: 16px;
        font-weight: bold;
        line-height: 21px;
        letter-spacing: 2px;
        color: #ffffff;
        margin-bottom: 60px;
      }

      .forgot {
        float: right;
        display: inline;
      }

      .submit {
        width: 100%;
      }
    }
  }
}
</style>
